package com.sporadic.backstage.service.serviceImpl;

import com.sporadic.backstage.dto.StoreProfileDTO;
import com.sporadic.backstage.entity.Order;
import com.sporadic.backstage.mapper.OrderMapper;
import com.sporadic.backstage.mapper.UserMapper;
import com.sporadic.backstage.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService
{

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserMapper userMapper;


    @Override
    public List<Order> selTop3TotalCountUser(Integer merchantId) {
        return orderMapper.selTop3TotalCountUser(merchantId);
    }

    @Override
    public StoreProfileDTO findStoreProfile(Integer merchantId, Integer date) {
        StoreProfileDTO storeProfileDTO = orderMapper.findStoreProfile(merchantId,date);
        Double refundAmount = orderMapper.refundAmount(merchantId,date);
        storeProfileDTO.setRefundAmount(refundAmount==null? 0d:refundAmount);

        storeProfileDTO.setMembership(userMapper.findUserCount(merchantId));
        return storeProfileDTO;
    }

    @Override
    public List<String> findSalesAnalysis(Integer merchantId, Integer date) {
        return orderMapper.findSalesAnalysis(merchantId,date);
    }


}
